package com.dayaokeji.rhythmschoolstudent.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.dayaokeji.rhythmschoolstudent.client.common.VieAnswerActivity
import com.dayaokeji.rhythmschoolstudent.utils.UserUtils
import com.google.gson.Gson
import com.orhanobut.logger.Logger

/**
 *********************************************************************
 **  Created by Zeno on 2018/8/4
 *********************************************************************
 **  version 1.0
 *********************************************************************
 **  Copyright (C) dayaokeji.com 2018 -- 2020 All rights reserved.
 *********************************************************************
 **
 *********************************************************************
 */
class VieAnswerReceiver : BroadcastReceiver(){
    private val gson = Gson()
    override fun onReceive(context: Context?, intent: Intent?) {
        val message = intent?.getStringExtra("data")
        message?.let {
            Logger.d(message)
            if (UserUtils.hashLogin()) {
                val vieAnswerBean = gson.fromJson<VieAnswerBean>(it, VieAnswerBean::class.java)
                vieAnswerBean.isReply = true
                val userInfo = UserUtils.getUserInfo()
                userInfo?.let { user ->
                    val s1 = user.universityId.toString() + user.workNo
                    for (s in vieAnswerBean.recvUsers) {
                        if (s == s1) {
                            VieAnswerActivity.navigation(context!!, vieAnswerBean)
                        }
                    }
                }
            }
        }
    }
}